$(function () {
    setDefaultData();
});

function setDefaultData() {

    let cuisineId = sessionStorage.getItem("cuisineId");
    // console.log(cuisineId,111111111)
    if (cuisineId != "null") {
        getProductByCuisineId(cuisineId);
        sessionStorage.setItem("cuisineId",null);
    } else {
        // 默认显示所有菜系的第一页数据
        $.getJSON("../json/productNews.json", {}, function (data) {
            data = data.data;
            // let d = 0;
            let aa = [];
            for (let i = 0; i < data.length; i++) {
                let bb = data[i].data;
                for (let j = 0; j < bb.length; j++) {
                    // aa[d] = bb[j];
                    // d++;
                    aa.push(bb[j]);
                }
            }
            setProudctData(aa);
        });
    }


}

// 显示产品信息数据
function setProudctData(data) {
    let html = '';
    for (let i = 0; i < data.length; i++) {
        html += '<div>\n' +
            '                            <div><img src="' + data[i].img + '" height="300" width="300"/></div>\n' +
            '                            <div class="single-line-overflow">' + data[i].title + '</div>\n' +
            '                            <div>\n' +
            '                                <span>价格：</span><span>' + data[i].price + '</span>\n' +
            '                            </div>\n' +
            '                            <div class="many-line-overflow">' + data[i].content + '</div>\n' +
            '                        </div>';
    }
    $("#product").html(html);
}